package com.lvandroid.player.activity;

import android.os.Bundle;
import android.os.Environment;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.os.EnvironmentCompat;

import com.lvandroid.play.player.AllRoundPlayer;
import com.lvandroid.play.player.AllRoundPlayerManager;
import com.lvandroid.play.util.LogUtil;
import com.lvandroid.player.R;

import java.io.File;

public class PdfPlayerActivity extends AppCompatActivity {

    FrameLayout mContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdf_player);
        mContainer = findViewById(R.id.container);
    }

    @Override
    protected void onResume() {
        super.onResume();
        AllRoundPlayer player = AllRoundPlayerManager.createPlayer(
                AllRoundPlayerManager.MEDIA_TYPE_PDF);
        player.attachActivity(this);
        player.setDisplay(mContainer);
        File f = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
        String path = f.getAbsolutePath() + "/kotlin.pdf";
        LogUtil.i("PdfPlayerActivity", "onResume : " + path);
        File file = new File(path);
        if(file.exists()) {
            LogUtil.i("PdfPlayerActivity", "file exist!");
            player.setDataSource(path);
            player.start();
        }
    }
}